/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingServPoolPayOrderInfo: {
                fees: [],
                poolId: '',
                servName: '',
                feePrices: 0.0,
                codeUrl: ''
            }
        },
        _initMethod: function () {
            $that.housekeepingServPoolPayOrderInfo.poolId = vc.getParam('poolId');
            $that.housekeepingServPoolPayOrderInfo.servName = vc.getParam('servName');
            $that._loadPoolFees(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('housekeepingServPoolPayOrder', 'loadPoolFees', function (_param) {
                $that._loadPoolFees(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._loadPoolFees(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _loadPoolFees: function () {
                let _param = {
                    params: {
                        page: 1,
                        row: 50,
                        state: '1001',
                        poolId: $that.housekeepingServPoolPayOrderInfo.poolId,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                }
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderCartFee',
                    _param,
                    function (json, res) {
                        let _vipUserObj = JSON.parse(json);
                        let _feePrices = 0.0;
                        _vipUserObj.data.forEach(item => {
                            _feePrices += parseFloat(item.payPrice)
                        });
                        $that.housekeepingServPoolPayOrderInfo.feePrices = _feePrices;
                        $that.housekeepingServPoolPayOrderInfo.fees = _vipUserObj.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _payFee: function () {
                let _data = {
                    shopId: vc.getCurrentCommunity().shopId,
                    poolId: $that.housekeepingServPoolPayOrderInfo.poolId,
                }
                vc.http.apiPost(
                    '/payment/toQrServFeePay',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //谈二维码
                            $that.housekeepingServPoolPayOrderInfo.codeUrl = _json.codeUrl;
                            $that._viewQr(_json.codeUrl);
                            $('#payFeeResult').modal('show');
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            _back: function () {
                $('#payFeeResult').modal('hide');
                vc.goBack();
            },
            _viewQr: function (_url) {
                document.getElementById("qrcode").innerHTML = "";
                let qrcode = new QRCode(document.getElementById("qrcode"), {
                    text: "服务费用",  //你想要填写的文本
                    width: 200, //生成的二维码的宽度
                    height: 200, //生成的二维码的高度
                    colorDark: "#000000", // 生成的二维码的深色部分
                    colorLight: "#ffffff", //生成二维码的浅色部分
                    correctLevel: QRCode.CorrectLevel.H
                });
                qrcode.makeCode(_url);
            }
        }
    });
})(window.vc);
